#include <iostream>
#include "stock00.h"

Stock::Stock(const std::string &co, long n, double pt) {
  company = co;
  if (n < 0)
  {
      std::cout << "Number of shares can't be negative;"
                << company << " shares set to 0" << std::endl;
      shares = 0;
  }else{
      shares = n;
  }
  share_val = pt;
  set_total();
  isPrinted = false;
}

Stock::~Stock(){
    using namespace std;
    cout << "Bye " << company << endl;
}

void Stock::buy(long num, double price) {
    if (num < 0)
    {
        std::cout << "Number of shares purchased can't be negative;"
                  << "Transaction is aborted.\n";
    }
    else{
        shares += num;
        share_val = price;
        set_total();
    }
}

void Stock::sell(long num, double price) {
    using std::cout;
    if (num < 0)
    {
        cout << "Number of shares selled can't be negative;"
             << "Transaction is aborted.\n";
    }else if (num > shares)
    {
        cout << "You can't sell more than you have;"
             << "Transaction is aborted.\n";
    }else{
        shares -= num;
        share_val = price;
        set_total();
    }
}

void Stock::update(double price) {
    share_val = price;
    set_total();
}

void Stock::show() const
{
    std::cout << "Company:" << company
              << " Shares:" << shares
              << " Share Price: $" << share_val
              << " Total Worth: $" << total_val << "\n";
}
bool Stock::isPrinted = false;

void Stock::printStr(const std::string &astr){
    std::cout << "Print some string: " << astr << std::endl;
    isPrinted = true;
}